package com.aaa.order.controller;

import com.aaa.order.feign.ProductFeign;
import com.aaa.order.service.IOrderService;
import entity.Order;
import entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private ProductFeign productFeign;


    @Autowired
    private IOrderService orderService;

    @GetMapping("/saveOrder")
    public Order saveOrder(Long pid,Integer num){
        Order order=new Order();
        //用户的信息可以从登录后获取--Session redis jwt
        order.setUid(1);
        order.setUsername("徐一山");
        //为订单对象设置商品的信息
        order.setPid(pid);
        Product product = productFeign.getById(pid);
        order.setPname(product.getPname());
        order.setPprice(product.getPprice());
        order.setNumber(num);
        orderService.save(order);
        return order;
    }
    @GetMapping("queryOrder")
    public String queryOrder(){
        orderService.queryGood();
        return "查询订单";
    }
    @GetMapping("addOrder")
    public String addOrder(){
        orderService.queryGood();
        return "添加订单";
    }
}
